/**********************************************************************
 * 项目：bilibili粉丝数监视器v1.1
 * 硬件：适用于NodeMCU ESP8266 + MAX7219
 * 功能：连接WiFi后获取指定用户的哔哩哔哩实时粉丝数并在8位数码管上居中显示
 * 作者：flyAkari 会飞的阿卡林 bilibili UID:751219
 * 日期：2018/09/18
 **********************************************************************/
/*2018/12/18更新说明：
  上电后数码管显示初始化为"--------", 直到获取到粉丝数.
  可从串口监视器输入数字测试显示连接是否正常, 波特率选择9600.*/

 //硬件连接说明：
 //MAX7219 --- ESP8266
 //  VCC   --- 3V(3.3V)
 //  GND   --- G (GND)
 //  DIN   --- D7(GPIO13)
 //  CS    --- D1(GPIO5)
 //  CLK   --- D5(GPIO14)
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <Ticker.h>
#include <Wire.h>
#include <ACROBOTIC_SSD1306.h>                 //OLED库
//---------------修改此处""内的信息--------------------
//const char* ssid     = "WHY";     //WiFi名
//const char* password = "WHYwhy12345"; //WiFi密码
String biliuid       = "179572402";           //bilibili UID
//----------------------------------------------------
DynamicJsonDocument jsonBuffer(400);
WiFiClient client;
Ticker blinker;
static unsigned char bilibili_logo[] PROGMEM ={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF1,0xF1,0xF3,0xF6,
0xFE,0xFC,0xF8,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF8,0xFC,0xFE,0xF7,0xF3,0xF1,
0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0xF0,0xF8,0xF8,0xF8,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF8,0xF8,0xF8,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x3F,0x1F,0x1F,0x1F,0x0F,0x8F,0x8F,0x87,
0x87,0xC7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC7,0x87,
0x87,0x8F,0x0F,0x0F,0x1F,0x1F,0x1F,0x3F,0x3F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0x1F,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x78,0x78,0x78,0x40,0x00,0x03,0xFF,0xFF,0xFE,
0x00,0x00,0x00,0x78,0x00,0x78,0x78,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x78,0x78,
0x78,0x40,0x00,0x03,0x7F,0xFF,0xFF,0x00,0x00,0x00,0x78,0x78,0x78,0x78,0x00,0x00,
0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xEF,0x8F,0x1F,0x7F,0x7F,0x1F,0x8F,0x8F,0x1F,0x7F,0x7F,0x1F,0x8F,0xEF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFC,0xF0,0xF0,0xF0,0x70,0x70,0x70,0xF0,0xE0,
0xE0,0xE0,0xE0,0xE0,0xC0,0xC0,0x80,0x02,0x7E,0xFE,0xFE,0xF0,0x00,0x00,0x7F,0xFF,
0xF8,0x00,0x00,0x0E,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFC,0xF0,
0xF0,0xF0,0x70,0x70,0x70,0xF0,0xE0,0xE0,0xE0,0xE0,0xE0,0xC0,0xC0,0x80,0x02,0x3E,
0xFE,0xFE,0xF8,0x00,0x00,0x3F,0xFF,0xFC,0x00,0x00,0x06,0xFE,0xFE,0xFE,0x00,0x00,
0x00,0x00,0x07,0x0F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x7F,0x7F,0x7F,0x7F,0x1F,0x1F,
0x1F,0x1F,0x1F,0x1F,0x1E,0x1E,0x1F,0x1F,0x1F,0x1F,0x1E,0x1E,0x1F,0x1F,0x1F,0x7F,
0x7F,0x7F,0x7F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x3F,0x3F,0x3F,0x3F,0x3F,0x38,0x18,0x18,0x1C,0x1C,
0x1E,0x0F,0x0F,0x0F,0x07,0x07,0x03,0x00,0x00,0x07,0x0F,0x0F,0x00,0x00,0x00,0x17,
0x07,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x07,0x3F,0x3F,0x3F,
0x3F,0x3F,0x38,0x18,0x18,0x1C,0x1C,0x1E,0x0F,0x0F,0x0F,0x07,0x07,0x03,0x00,0x00,
0x0F,0x1F,0x1F,0x18,0x00,0x00,0x07,0x07,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00             //,C:\Users\Why\Pictures\bilibili.bmp0
};
static unsigned char wifi_error[] PROGMEM {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x30,0x60,0xC0,
0x80,0x80,0xF0,0x1C,0x3C,0xE0,0x80,0x80,0xC0,0x60,0x30,0x18,0x00,0x00,0x00,0x00,
0xEC,0xEC,0x00,0x00,0x00,0x00,0xFC,0xFC,0x6C,0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,
0xEC,0xEC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xC0,0xE0,0xE0,0xF0,0x38,0x1C,0x1C,0x1E,0x8E,0x8F,0xCF,0xCF,0xCF,
0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,0xCF,
0x8F,0x8F,0x8F,0x8F,0x8F,0x8E,0x0E,0x1C,0x3C,0x7C,0xF8,0xF0,0xC0,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,
0x83,0x83,0x80,0x80,0x00,0x01,0x03,0x83,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x03,0x03,0x80,0x80,0x80,0x80,0x83,0x83,0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x80,
0x83,0x83,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x03,0x03,0x03,0x01,0x00,0x3C,0x3C,0x3F,0x0F,0x03,0xE1,0xF1,0x79,0x18,
0x0C,0x8C,0xC4,0xE4,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0xE4,0xC4,0x8C,0x1C,
0x3D,0x71,0xE1,0xC3,0x83,0x07,0x0F,0x3E,0x3C,0x38,0x00,0x01,0x01,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x61,0x61,
0x61,0x61,0x61,0x61,0x00,0x00,0x00,0xFF,0xFF,0x40,0x40,0x60,0x60,0x31,0x1F,0x00,
0x00,0x00,0xFF,0xFF,0x40,0x40,0x60,0x60,0x31,0x1F,0x00,0x00,0x00,0xFF,0x01,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0xFF,0xFF,0x40,0x40,0x60,0x60,0x31,
0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,
0x03,0x03,0x03,0x01,0x0C,0x0E,0x0F,0x0F,0x0F,0x0F,0x0E,0x0C,0x01,0x03,0x03,0x03,
0x00,0x00,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x18,0x18,
0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x1F,0x1F,0x03,0x02,0x06,0x0E,0x1C,0x18,0x00,
0x00,0x00,0x1F,0x1F,0x03,0x02,0x06,0x0E,0x1C,0x18,0x00,0x00,0x00,0x0F,0x18,0x10,
0x10,0x10,0x10,0x10,0x18,0x0F,0x00,0x00,0x00,0x1F,0x1F,0x03,0x03,0x06,0x0E,0x1C,
0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  //,C:\Users\NiGv\Desktop\error3.BMP0  
};

int number = 0;
char clean=0,display_flag=1,error_flag=0;
void setup()
{
  Serial.begin(9600);
  Serial.println("bilibili fans monitor, version v1.1");
  Wire.begin();  
  oled.init();                          // Initialze SSD1306 OLED display
  oled.clearDisplay();                  // Clear screen
    
  blinker.attach_ms(1,checkInput); //开启监听串口输入功能


  // 必须采用 AP 与 Station 兼容模式
  WiFi.mode(WIFI_AP_STA);
  delay(500);


 // 等待配网
  WiFi.beginSmartConfig();

 // 收到配网信息后ESP8266将自动连接，WiFi.status 状态就会返回：已连接
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    // 完成连接，退出配网等待。
    Serial.println(WiFi.smartConfigDone());

  oled.setTextXY(0,0); 
  oled.putString("Connect wifi");
  
  oled.setTextXY(3,number); 
  oled.putString("."); 
  number++;
  delay(40);
  if(number>=15)
  {
    number=0;
   oled.setTextXY(3,0); 
   oled.putString("                "); 
   }
  }
  oled.clearDisplay();                  // Clear screen
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  oled.drawBitmap(bilibili_logo, 1024);   // 1024 pixels for logo
  oled.setTextXY(0,0); 
  oled.putString("Your fans:");

}

void loop()
{
  if (WiFi.status() == WL_CONNECTED) //此处感谢av30129522视频作者的开源代码
  {
    HTTPClient http;
    http.begin("http://api.bilibili.com/x/relation/stat?vmid=" + biliuid);
    auto httpCode = http.GET();
    Serial.print("HttpCode:");
    Serial.print(httpCode);


    if(((display_flag==0)&&(clean==0))||((error_flag==1)&&(httpCode>1)))
    {
      display_flag=1;
      oled.clearDisplay();                  // Clear screen
      oled.drawBitmap(bilibili_logo, 1024);   // 1024 pixels for logo
      oled.setTextXY(0,0); 
      oled.putString("Your fans:");    
    }
    
    if (httpCode > 0) {
      error_flag=0;
      String resBuff = http.getString();
      DeserializationError error = deserializeJson(jsonBuffer, resBuff);
      if (error) {
        Serial.println("json error");
        while (1);
      }
      JsonObject root = jsonBuffer.as<JsonObject>();
      long code = root["code"];
      Serial.print("     Code:");
      Serial.print(code);
      long fans = root["data"]["follower"];
      Serial.print("     Fans:");
      Serial.println(fans);
 
      oled.setTextXY(0,42);                 // Set cursor position, start of line 4   
      oled.putNumber(fans);
      delay(20);
    }
   else if((httpCode < 0)&&(error_flag==0))
   {
    error_flag=1;
    oled.clearDisplay();                  // Clear screen
    oled.drawBitmap(wifi_error, 1024);   // 1024 pixels for logo
   }  
  }

   
     // 收到配网信息后ESP8266将自动连接，WiFi.status 状态就会返回：已连接
   while (WiFi.status() != WL_CONNECTED) {
          display_flag=0;
          if(clean==0)
          {
              clean=1;
              oled.clearDisplay();                  // Clear screen
          }
          delay(500);
          Serial.print(".");
          // 完成连接，退出配网等待。
          Serial.println(WiFi.smartConfigDone());
      
        oled.setTextXY(0,0); 
        oled.putString("Connect wifi");
        
        oled.setTextXY(3,number); 
        oled.putString("."); 
        number++;
        delay(40);
        if(number>=15)
        {
          number=0;
         oled.setTextXY(3,0); 
         oled.putString("                "); 
         }
       }
     clean=0;

   
}

void checkInput()
{
  if (Serial.available())   //Test number display
  {
    char ch = Serial.read();
    if (ch == '\n')
    {
      Serial.println(number);
      number = 0;
    }
    else
    {
      number = (number * 10) + ch - '0';
    }
  }
}
